STDOUT.sync = true
require 'Json.rb'

filename = "tmp_json_status.txt"
url = "localhost"
path_status = "/cgi-bin/Game/status.cgi"
port = 10080
filename = "output_cgi-status.txt"

#data = Json::get_json(url, path_status, port)
data = Json::get_json_from_file("output_cgi-status.txt")

#Json::write_jsonfile(filename, data)

result_jobs = nil
data["Users"]["USER1"]["MasterJobs"].each {|job|
	jobid = job[0]
p job
	puts "------"
	if (job[1]["Result"] == "success.") then
		result_jobs = Json::parse_json(job[1]['Value'])
		break
	else
		puts "(SKIP)"
	end
	puts "------"
}


result_jobs.sort {|a,b| a[1]["StartString"] <=> b[1]["StartString"]}.each {|result|
#		p result[1]

		printf("Status:[%s] Block:[%-8s : %-8s]\n",
			result[1]["Status"], result[1]["StartString"], result[1]["EndString"])

		answers = result[1]["Result"]
		answers.sort {|a, b| a[0].size <=> b[0].size}.each {|answer|
			printf("  [%8s] x %s\n", answer[0], answer[1]["Number"])
		}


}

